package com.rabbitmq.exec.direct;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.exec.fanout.EmitLog;
import com.rabbitmq.exec.utils.RabbitMqUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @Description
 * @Author lhj
 * @Date 2024/4/14 16:55
 */
public class EmitLogDirect {
    static final Logger logger = LoggerFactory.getLogger(EmitLogDirect.class);

    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {
        try (Channel channel = RabbitMqUtils.getChannel()) {
            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
            logger.info("生产者发送确认消息:");
            Map<String, String> map = new HashMap<>();
            map.put("info", "生产者发送info级别的日志");
            map.put("warning", "生产者发送warning级别的日");
            map.put("error", "生产者发送error级别的日志");
            map.put("debug", "生产者发送debug级别的日志");
            for (Map.Entry<String, String> entry : map.entrySet()) {
                String routingKey = entry.getKey();
                String message = entry.getValue();
                channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes(StandardCharsets.UTF_8));
                logger.info("生产者发送direct消息, exchange: {} , routingKey: {}, message: {}", EXCHANGE_NAME, routingKey, message);
            }
        }
    }

}
